<template>
  <div>
      <f-table ref="table" size="small" rowKey="processId" :columns="columns" :scroll="{x:true}" :multiple="false" :operator="operator" :params="queryParam" :api="api.tasktodo" handler="customBondTaskTodoListHandler">

        <span slot="action" slot-scope="text, record">
          <template>
            <a v-if="record.endTime==''&&record.assignee!=''&& record.assignee!=''" @click="$refs.drawer.showDrawer(record)">办理</a>
            <a v-if="record.assignee==''||record.assignee==''" @click="claimTask(record)">认领</a>
             <a-divider type="vertical"/>
              <a href="javascript:;" @click="$refs['refund'].showDrawer(record,'form2')" v-if="record.amountType=='Refund'">查看</a>
              <a href="javascript:;" @click="$refs['sbreturn'].showDrawer(record,'form2')" v-if="record.amountType=='SbReturn'">查看</a>
              <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
               <a-menu-item v-if="record.assignee===$store.getters.userInfo.nickName && record.endTime==''">
                <a href="javascript:;" @click="unClaimTask(record)">取消认领</a>
              </a-menu-item>
                <a-menu-item>
                <a href="javascript:;" @click="processImg(record)">流程图</a>
              </a-menu-item>
<!--              <a-menu-item v-if="$auth('table.delete')">-->
<!--                <a href="javascript:;" @click="$refs.table.del(record)">删除</a>-->
<!--              </a-menu-item>-->
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
      <task-todo-drawer ref="drawer" @success="onLoad" handler-name="refundFormTaskDataHandler"></task-todo-drawer>
      <process-image ref="processImg" v-if="processImageVisible" :visible.sync="processImageVisible" :processInstanceId="processInstanceId"></process-image>
      <refund-drawer ref="refund"></refund-drawer>
      <sbreturn-drawer ref="sbreturn" @success="onLoad"></sbreturn-drawer>
  </div>
</template>
<script>

  import api from './../js/api'
  import ProcessImage from '../../process/process_image'
  import TaskTodoDrawer from './../tasktodo_drawer'
  import OrderSupplierBondDrawer from '../../../business/order/supplierbond/supplierbond_drawer'
  import RefundDrawer from '../../../business/order/refund/refund_drawer'
  import SbreturnDrawer from '../../../business/order/sbreturn/sbreturn_drawer'
  export default {
    name: 'TableList',
    components: {
      TaskTodoDrawer,
      ProcessImage,
      RefundDrawer,
      SbreturnDrawer
    },
    data() {
      let me = this
      //操作按钮
      let operator = []

      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {},
        processInstanceId: '',
        processImageVisible: false,
        // 表头
        columns: [
          {
            title: '#',
            width: '60',
            align: 'center',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '操作',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          },
          {
            title: '单号',
            align: 'center',
            dataIndex: 'paymentNo'
          },
          {
            title: '保证金金额',
            align: 'center',
            dataIndex: 'amount'
          },
          {
            title: '收款日期',
            align: 'center',
            dataIndex: 'amountDate'
          },
          {
            title: '审批人',
            align: 'center',
            dataIndex: 'assignee'
          },
          {
            title: '审批状态',
            align: 'center',
            dataIndex: 'taskName'
          },
          {
            title: '制单人',
            align: 'center',
            dataIndex: 'nickName'
          },
          {
            title: '创建日期',
            align: 'center',
            dataIndex: 'createTime'
          }
        ],
        operator: operator
      }
    },
    created() {
    },
    methods: {
      onLoad() {
        this.$refs.table.refresh()
      },
      claimTask(task) {
        this.http.put(this, {
          url: this.api.tasktodo.claim,
          data: {
            taskId: task.taskId
          },
          success(me, data) {
            me.$refs['table'].refresh(false)
          }
        })
      },
      processImg(task) {
        this.processInstanceId = task.processInstanceId
        this.processImageVisible = true
      },
      /**
       * 查询事件
       * @param searchParams
       */
      searchTable(searchParams) {
        this.queryParam = Object.assign(this.queryParam, searchParams)
        this.$refs.table.refresh(true, searchParams)
      },
      unClaimTask(task) {
        this.http.put(this, {
          url: this.api.tasktodo.unclaim,
          data: {
            taskId: task.taskId
          },
          success(me, data) {
            me.$refs['table'].refresh(false)
          }
        })
      }
    }
  }
</script>
